package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Payment;
import cn.wolfcode.crm.query.PaymentQueryObject;
import cn.wolfcode.crm.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.math.BigDecimal;
import java.util.List;

@Controller
public class PaymentPieController {
    @Autowired
    private IPaymentService paymentService;

    @RequestMapping("paymentPie")
    public String index(Model model, PaymentQueryObject qo){
        int payClass1=0;
        int payClass2=0;
        int payClass3=0;
        int payClass4=0;
        int payClass5=0;
        int payClass6=0;


        List<Payment> payments = paymentService.selectAll();
        BigDecimal allAmount = paymentService.allAmount(qo);
        for (Payment payment : payments) {


            if(payment.getPayclassify().getName().equals("采购费")){
                payClass1++;

            }
            if(payment.getPayclassify().getName().equals("维修费")){
                payClass2++;
            }
            if(payment.getPayclassify().getName().equals("物业费")){
                payClass3++;
            }
            if(payment.getPayclassify().getName().equals("水电费")){
                payClass4++;
            }
            if(payment.getPayclassify().getName().equals("快递费")){
                payClass5++;
            }
            if(payment.getPayclassify().getName().equals("聚餐费")){
                payClass6++;
            }

        }


        model.addAttribute("payClass1",(float)payClass1/payments.size());
        model.addAttribute("payClass2",(float)payClass1/payments.size());
        model.addAttribute("payClass3",(float)payClass1/payments.size());
        model.addAttribute("payClass4",(float)payClass1/payments.size());
        model.addAttribute("payClass5",(float)payClass1/payments.size());
        model.addAttribute("payClass6",(float)payClass1/payments.size());
        model.addAttribute("allAmount",allAmount);
        return "paymentPie";
    }


}
